package com.li.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 *
 * Created by Li on 2016/7/7.
 */
public abstract class CommonAdapter<T> extends BaseAdapter {

    private Context context;
    private List<T> data;
    private final int layoutId;

    public CommonAdapter(Context context, List<T> data, int layoutId) {
        this.layoutId = layoutId;
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public T getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder = getHolder(context, convertView, position, parent);
        convert(holder,getItem(position));
        return holder.getConvertView();
    }
    private ViewHolder getHolder(Context context,View convertView, int position,ViewGroup parent){
        return ViewHolder.get(context,layoutId,convertView,position,parent);
    }
    public abstract void convert(ViewHolder holder, T item );

}
